  /**
    * 网络公共类
    * by dily
    * (c) copyright 2014 - 2035
    * All Rights Reserved. 
    * 存放网络公共方法 
    * 注意：是异步请求
    */
module Network {

    //发送消息
    //url 网络地址
    //data exp "name='dily'&age:18"
    export function sendInfo(url: string = "",urlData: string = ""): void {
        Global.waitPanel = new WaitPanel(1);
        GameConfig.gameScene().maskLayer.removeChildren();
        GameConfig.gameScene().maskLayer.addChild(Global.waitPanel);
        var loader: egret.URLLoader = new egret.URLLoader();
        loader.dataFormat = egret.URLLoaderDataFormat.TEXT;
        loader.addEventListener(egret.Event.COMPLETE,onGetComplete,this);
        loader.addEventListener(egret.IOErrorEvent.IO_ERROR, onLoadError, this);
        var request: egret.URLRequest = new egret.URLRequest(url);
        request.method = egret.URLRequestMethod.POST;
        request.data = new egret.URLVariables(urlData);
        loader.load(request);
    }
    
    //GET请求完成
    //发送消息 消息为 网址名称
    export function onGetComplete(event: egret.Event): void {
        GameConfig.gameScene().maskLayer.removeChild(Global.waitPanel);
        Global.waitPanel = null;
        var loader: egret.URLLoader = <egret.URLLoader> event.target;
        loader.dataFormat = egret.URLLoaderDataFormat.TEXT;
        var data: egret.URLVariables = loader.data;
        var data2;
        if(data.toString() != "") {
            data2 = eval("(" + data + ")");
        }
        var notify: string = loader["_eventTarget"]._request.url;
        lcp.LListener.getInstance().dispatchEvent(new lcp.LEvent(notify,data2,false));
    }
    export function onLoadError(): void {
        GameConfig.gameScene().maskLayer.removeChild(Global.waitPanel);
        Global.waitPanel = null;
        Global.alert("提示","请求失败。",null,1);
    }
	
    export function sendSmallInfo(url: string = "",urlData: string = ""): void {
        var loader: egret.URLLoader = new egret.URLLoader();
        loader.dataFormat = egret.URLLoaderDataFormat.TEXT;
        loader.addEventListener(egret.Event.COMPLETE,onGetSmallComplete,this);
        loader.addEventListener(egret.IOErrorEvent.IO_ERROR, onSmallLoadError, this);
        var request: egret.URLRequest = new egret.URLRequest(url);
        request.method = egret.URLRequestMethod.POST;
        request.data = new egret.URLVariables(urlData);
        loader.load(request);
    }
    export function onGetSmallComplete(event: egret.Event): void {
        var loader: egret.URLLoader = <egret.URLLoader> event.target;
        loader.dataFormat = egret.URLLoaderDataFormat.TEXT;
        var data: egret.URLVariables = loader.data;
        var data2;
        if(data.toString() != "") {
            data2 = eval("(" + data + ")");
        }
        var notify: string = loader["_eventTarget"]._request.url;
        lcp.LListener.getInstance().dispatchEvent(new lcp.LEvent(notify,data2,false));
    }
    export function onSmallLoadError(): void {
        Global.alert("提示","请求失败",null,1);
    }
    
}

